yjx.controller('reservationController',['$rootScope','$scope','$stateParams','$fetch','modalService','$timeout',function ($rootScope,$scope,$stateParams,$fetch,modalService,$timeout) {
    var productId = $stateParams.id;
    var activityId = $stateParams.activityId;
    var reserIds = [];
    var clientListApi='/customer/getList';
    $rootScope.tabCtrlName = $rootScope.tabCtrlNameArr[1];
    /*模拟数据以下*/

    /*模拟数据以上*/
    /*获取客户列表*/
    function getClientList() {
        $fetch.fetch(
            clientListApi,
            {
                params:{
                    userId:$rootScope.userId
                },
                cache:false,
            }
        ).then(function (data) {
                $timeout(function(){
                    if(data) {
                        $scope.reservationList = data
                        console.log( $scope.reservationList);
                    }
                })
            }).catch(function (e) {
                modalService.mainMsgError(e.msg);
            })
    }
    getClientList();

    /*选择客户*/
    $scope.onClick = function (id) {
        var count = 0
        if(reserIds && reserIds.length>0) {
            for(var i in reserIds) {
                count++;
                if(reserIds[i] == id) {
                    //console.log("ddddddddddd")
                    reserIds.splice(i,1);
                    //console.log(reserIds)
                    return;
                }else if(count == reserIds.length) {
                    reserIds.push(id);
                }
            }
        }else{
            reserIds.push(id);
        }
    }
    /*点击预约*/
    $scope.reservation = function() {
        var type = 2;
        if(activityId != null && activityId >0 ){
            type=3
        }
        if(reserIds && reserIds.length >0) {
            /*调接口*/
            $fetch.fetch(
                '/customer/bespeak',
                {
                    params:{
                        userId:$rootScope.userId,
                        customerIds:reserIds.join(','),
                        productId:productId,
                        activityId:activityId,
                        type:type
                    },
                    cache:false
                }
            ).then(function(data){
                    history.back();
                    modalService.mainMsgInfo("待办事项中将出现这些提醒",'','预约成功')
                }).catch(function(e){
                    modalService.mainMsgError(e.msg);
                })
        }
    }

}])

yjx.directive('reserliActive',[function(){
    return{
        restrict:'EA',
        link:function($scope,elem,attr){
            elem.bind('click',function(){
                if(elem.hasClass('active')){
                    elem.removeClass('active');
                }else{
                    elem.addClass('active');
                }
            })
        }
    }
}])
